/**
 * 视图模型（包括菜单及按钮）
 * Created by benben on 14-8-28.
 */
var db = require('./../../utils/mongodb/db');

function View(view) {
    this.id = view.id;
    this.code = view.code; //代码
    this.text = view.text; //文本描述
    this.children = view.children; //所有的子节点(Json串)
    this.status = view.status; //0是删除，1一层节点，2-8 二层节点，9按钮
    this.leaf = view.leaf; //是否为叶子,status 2-8
};

var Schema = db.Schema;
var viewSchema  = new Schema({
//    _id: ObjectId ,
    code: String ,
    text: String ,
    status: Number ,
    leaf: Boolean ,
    children: [
        {
            code: String ,
            text: String ,
            status: Number ,
            leaf: Boolean
        }
    ]
});

var View = db.model('views',viewSchema);

module.exports = View;


View.get = function(user, callback) {

    db.get('views').find({status:1}, function(err, doc) {
        if (doc) {
            callback(err, doc);
        } else {
            callback(err, null);
        }
    });
};